project(JTK)

find_package(PkgConfig)

pkg_check_modules(CAIRO "cairo")

find_library(CAIRO_LIBRARY cairo ${CAIRO_LIBRARY_DIRS})

# Hack: to be safe, we should use ${CAIRO_LIBRARIES} here, 
# but I just don't want to link with those unused libs.
set(EXTRA_LIBS         ${CAIRO_LIBRARY})
set(EXTRA_LIB_DIRS     ${CAIRO_LIBRARY_DIRS})
set(EXTRA_INCLUDE_DIRS ${CAIRO_INCLUDE_DIRS})

if (GUI STREQUAL "gtk")
    pkg_check_modules(GTK   "gtk+-2.0")
    
    if (GTK_FOUND)
        set(EXTRA_LIBS         ${EXTRA_LIBS}         ${GTK_LIBRARIES})
        set(EXTRA_LIB_DIRS     ${EXTRA_LIB_DIRS}     ${GTK_LIBRARY_DIRS})
        set(EXTRA_INCLUDE_DIRS ${EXTRA_INCLUDE_DIRS} ${GTK_INCLUDE_DIRS})
        set(JTK_SOURCES jtk-gtk.c)
    else (GTK_FOUND)
        message(FATAL_ERROR "GTK+ 2.x not found.")
    endif (GTK_FOUND)

else (GUI STREQUAL "gtk")

    if (APPLE)
        find_library(COCOA_LIBRARY Cocoa)
        set(EXTRA_LIBS ${EXTRA_LIBS} ${COCOA_LIBRARY})
        set(JTK_SOURCES jtk-cocoa.m)
    endif (APPLE)

endif (GUI STREQUAL "gtk")

set(JTK_SOURCES ${JTK_SOURCES} jtk.c)

link_directories(${EXTRA_LIB_DIRS})
include_directories(${JTK_SOURCE_DIR} ${EXTRA_INCLUDE_DIRS})

add_library(jtk SHARED ${JTK_SOURCES})
target_link_libraries(jtk ${EXTRA_LIBS})

